package cn.zust.ly.EyExample.Ez53;

import java.util.Scanner;

/**
 * Created by liy on 2016/11/25.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        while (num-- > 0) {
            int n = sc.nextInt();
            int a[] = new int[n],b[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nextInt();
            for (int i = 0; i < n; i++)
                b[i] = sc.nextInt();
            for (int i = 0; i < n-1; i++) {
                for (int j = i+1; j < n; j++) {
                    if (a[i] > a[j]) {
                        int k = a[i];
                        a[i] = a[j];
                        a[j] = k;
                    }
                }
            }
            for (int i = 0; i < n-1; i++) {
                for (int j = i+1; j < n; j++) {
                    if (b[i] < b[j]) {
                        int k = b[i];
                        b[i] = b[j];
                        b[j] = k;
                    }
                }
            }
            int s = 0;
            for (int i = 0; i < n; i++) {
                s += a[i]*b[i];
            }

            System.out.println(s);
        }

    }
}
